package com.ucw.ucwclient.biz.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ucw.ucwclient.dal.dataobject.SchoolBanner;
import com.ucw.ucwclient.dal.dataobject.UActivity;
import com.ucw.ucwclient.dal.dataobject.UPlan;
import com.ucw.ucwclient.dal.dataobject.USchoolCommonweal;
import com.ucw.ucwclient.dal.dataobject.UStudy;
import com.ucw.ucwclient.dal.dataobject.UStudyBanner;
import com.ucw.ucwclient.dal.mapper.SchoolBannerMapper;
import com.ucw.ucwclient.dal.mapper.UActivityMapper;
import com.ucw.ucwclient.dal.mapper.UItemMapper;
import com.ucw.ucwclient.dal.mapper.UPlanMapper;
import com.ucw.ucwclient.dal.mapper.USchoolCommonwealMapper;
import com.ucw.ucwclient.dal.mapper.UStudyCollectMapper;
import com.ucw.ucwclient.dal.mapper.UStudyEnrollMapper;
import com.ucw.ucwclient.dal.mapper.UStudyMapper;

@Service
public class UCityService {
	@Resource
	private UStudyMapper uStudyMapper;

	@Resource
	private UStudyCollectMapper uStudyCollectMapper;

	@Resource
	private UStudyEnrollMapper uStudyEnrollMapper;

	@Resource
	private SchoolBannerMapper schoolBannerMapper;

	@Resource
	private UActivityMapper uActivityMapper;

	@Resource
	private UItemMapper uItemMapper;

	@Resource
	private UPlanMapper uPlanMapper;

	@Resource
	private USchoolCommonwealMapper wealMapper;

	public UStudyBanner getBanners(int schoolId) {

		List<SchoolBanner> sb = schoolBannerMapper.selectBySchoolId(schoolId);
		if (sb != null && sb.size() > 0) {
			List<UActivity> activity = new ArrayList<UActivity>();
			List<UStudy> uStudy = new ArrayList<UStudy>();
			List<UPlan> uPlan = new ArrayList<UPlan>();
			for (SchoolBanner schoolBanner : sb) {
				switch (schoolBanner.getType()) {
				// 1:校园赛事活动 3:出行活动 4:校园学习活动
				case 1:
					activity.add(uActivityMapper.selectByPrimaryKey(schoolBanner.getJumpId()));
					break;
				case 3:
					uPlan.add(uPlanMapper.selectByPrimaryKey(schoolBanner.getJumpId()));
					break;
				case 4:
					uStudy.add(uStudyMapper.selectByPrimaryKey(schoolBanner.getJumpId()));
					break;
				default:
					break;
				}
				UStudyBanner returnData = new UStudyBanner();
				returnData.setActivity(activity);
				returnData.setuPlan(uPlan);
				returnData.setuStudy(uStudy);
				return returnData;
			}
		}
		return null;
	}

	public USchoolCommonweal getCommonweal(int schoolId, int type) {
		return wealMapper.selectBySchoolAType(schoolId, type);
	}

	public Map<String, String> addOne(USchoolCommonweal entity, Long userId) {
		entity.setCreateTime(new Date());
		entity.setUserId(userId);
		int result = wealMapper.insertSelective(entity);

		Map<String, String> resp = new HashMap<String, String>();
		if (result == 1) {
			resp.put("resultMsg", "success");
			resp.put("code", "200");
		} else {
			resp.put("resultMsg", "fail");
		}
		return resp;
	}
}
